﻿using UnityEngine;
using Vector2 = System.Numerics.Vector2;

namespace susi.util.math {
    /// <summary>
    /// 常用算法库
    /// </summary>
    public class MathLibrary {

        #region remap

        public static int Remap(int x, int xrange_x, int xrange_y, int newrange_x, int newrange_y)
        {
            return (x - xrange_x) / (xrange_y - xrange_x) * (newrange_y - newrange_x) + newrange_x;
        }

        public static float Remap(float x, float xrange_x, float xrange_y, float newrange_x, float newrange_y)
        {
            return (x - xrange_x) / (xrange_y - xrange_x) * (newrange_y - newrange_x) + newrange_x;
        }

        public static double Remap(double x, double xrange_x, double xrange_y, double newrange_x, double newrange_y)
        {
            return (x - xrange_x) / (xrange_y - xrange_x) * (newrange_y - newrange_x) + newrange_x;
        }

        public static decimal Remap(decimal x, decimal xrange_x, decimal xrange_y, decimal newrange_x, decimal newrange_y)
        {
            return (x - xrange_x) / (xrange_y - xrange_x) * (newrange_y - newrange_x) + newrange_x;
        }

        public static long Remap(long x, long xrange_x, long xrange_y, long newrange_x, long newrange_y)
        {
            return (x - xrange_x) / (xrange_y - xrange_x) * (newrange_y - newrange_x) + newrange_x;
        }

        #endregion
       
    }

    public static class MathExtension {
        public static float Abs(this float flo)
        {
            return System.Math.Abs(flo);
        }

        public static int Abs(this int i) => System.Math.Abs(i);
        
    }
}